﻿using OneSpider.DbContexts;
using One.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Remoting.Contexts;


namespace OneSpider.Helper
{
    public class DatabaseHelper<T> where T : class
    {
        private static OneDataContext context = new OneDataContext();

        public static int Insert(T t)
        {
            context.Set<T>().Add(t);
            try
            {
                return context.SaveChanges();
            }
            catch (Exception)
            {
                return -1;
            }
        } 

        public static int Insert(IEnumerable<T> entities)
        {
            //context.BulkInsert(entities);
            context.Set<T>().AddRange(entities);
            try
            {
                return context.SaveChanges();
            }
            catch(Exception )
            {
                return -1;
            }
        }
    }
}
